﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RenameTool.Rules.CUiAppend
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Markup;
using Tecnomatix.Engineering;
using Tecnomatix.Planning.DotNetComponents;


namespace DnProcessSimulateCommands.RenameTool.Rules;

public class CUiAppend : RuleWindowBase, IComponentConnector
{
  internal System.Windows.Controls.RadioButton rbPrefix;
  internal System.Windows.Controls.RadioButton rbSuffix;
  internal System.Windows.Controls.RadioButton radioButtonAppend;
  internal System.Windows.Controls.TextBox textBoxAppend;
  internal System.Windows.Controls.TextBox textBoxEnum;
  internal System.Windows.Controls.TextBox textBoxStep;
  internal System.Windows.Controls.CheckBox unlimitedChkBx;
  internal System.Windows.Controls.Button buttonAddEnumerator;
  internal System.Windows.Controls.Button buttonAddAttribute;
  internal System.Windows.Controls.RadioButton radioButtonTrim;
  internal System.Windows.Controls.TextBox textBoxTrim;
  internal System.Windows.Controls.RadioButton radioButtonTrimDigits;
  internal System.Windows.Controls.Button btnOK;
  internal System.Windows.Controls.Button btnCancel;
  private bool _contentLoaded;

  public CUiAppend(Window parent)
  {
    this.InitializeComponent();
    ((Window) this).Owner = parent;
    System.Windows.Controls.RadioButton radioButtonAppend = this.radioButtonAppend;
    radioButtonAppend.Content = (object) (radioButtonAppend.Content?.ToString() + ":");
    System.Windows.Controls.RadioButton radioButtonTrim = this.radioButtonTrim;
    radioButtonTrim.Content = (object) (radioButtonTrim.Content?.ToString() + ":");
    this.textBoxAppend.Focus();
    // ISSUE: explicit non-virtual call
    __nonvirtual (((Window) this).Title) = XamlResourceManager.GetString("RENAME_TOOL_TITLE_APPEND");
    if (CApRenameToolManager.GetInstance().IsRunningInDesigner())
      return;
    this.buttonAddAttribute.Visibility = Visibility.Collapsed;
    ((FrameworkElement) this).MinHeight = ((FrameworkElement) this).MinHeight - 29.0;
    ((FrameworkElement) this).MaxHeight = ((FrameworkElement) this).MaxHeight - 29.0;
  }

  public RuleWindowBase CreateWindow(Window parent) => (RuleWindowBase) new CUiAppend(parent);

  public override object[] Args
  {
    get
    {
      object[] args = new object[3]
      {
        (object) this.rbPrefix.IsChecked.Value,
        null,
        null
      };
      bool? isChecked1 = this.radioButtonAppend.IsChecked;
      bool flag1 = true;
      if (isChecked1.GetValueOrDefault() == flag1 & isChecked1.HasValue)
      {
        args[1] = (object) 0;
        args[2] = (object) this.textBoxAppend.Text;
      }
      else
      {
        bool? isChecked2 = this.radioButtonTrim.IsChecked;
        bool flag2 = true;
        if (isChecked2.GetValueOrDefault() == flag2 & isChecked2.HasValue)
        {
          args[1] = (object) 1;
          args[2] = (object) this.textBoxTrim.Text.Trim();
        }
        else
        {
          args[1] = (object) 2;
          args[2] = (object) "";
        }
      }
      return args;
    }
    set
    {
      if (value.Length != 3)
        throw new FormatException("Three values expected.");
      this.rbPrefix.IsChecked = value[0] is bool && value[1] is int && value[2] is string ? new bool?((bool) value[0]) : throw new FormatException("Wrong types supplied.");
      this.rbSuffix.IsChecked = new bool?(!(bool) value[0]);
      this.radioButtonAppend.IsChecked = new bool?(false);
      this.radioButtonTrim.IsChecked = new bool?(false);
      this.radioButtonTrimDigits.IsChecked = new bool?(false);
      if ((int) value[1] == 0)
      {
        this.radioButtonAppend.IsChecked = new bool?(true);
        this.textBoxAppend.Text = (string) value[2];
      }
      else if ((int) value[1] == 1)
      {
        this.radioButtonTrim.IsChecked = new bool?(true);
        this.textBoxTrim.Text = (string) value[2];
      }
      else
      {
        if ((int) value[1] != 2)
          return;
        this.radioButtonTrimDigits.IsChecked = new bool?(true);
      }
    }
  }

  private void btnOK_Click(object sender, RoutedEventArgs e)
  {
    ((Window) this).DialogResult = new bool?(true);
  }

  public override RuleMessage Validate()
  {
    uint result;
    return this.radioButtonAppend.IsChecked.Value ? (this.textBoxAppend.Text == "" ? new RuleMessage(false, XamlResourceManager.GetString("RENAME_TOOL_APPEND_OR_TRIM_WRONG_APPEND")) : new PartialStringParser().Parse(this.textBoxAppend.Text)) : (this.radioButtonTrim.IsChecked.Value && (!uint.TryParse(this.textBoxTrim.Text.Trim(), out result) || result == 0U) ? new RuleMessage(false, XamlResourceManager.GetString("RENAME_TOOL_APPEND_OR_TRIM_WRONG_TRIM")) : new RuleMessage(true));
  }

  private void buttonAddEnumerator_Click(object sender, RoutedEventArgs e)
  {
    if (this.textBoxEnum.Text == "")
    {
      int num1 = (int) TxMessageBox.Show(XamlResourceManager.GetString("RENAME_TOOL_PARSER_WRONG_ENUM"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    else
    {
      string enumeratorString = PartialStringParser.GetEnumeratorString(this.textBoxEnum.Text, this.textBoxStep.Text, this.unlimitedChkBx.IsChecked.Value);
      RuleMessage ruleMessage = new PartialStringParser().Parse(enumeratorString);
      if (!ruleMessage.Success)
      {
        int num2 = (int) TxMessageBox.Show(ruleMessage.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
      else
        this.textBoxAppend.Text += enumeratorString;
    }
  }

  private void textBox_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
  {
    if (!(sender is System.Windows.Controls.TextBox))
      return;
    System.Windows.Controls.TextBox textBox = sender as System.Windows.Controls.TextBox;
    if (!textBox.IsEnabled)
      return;
    textBox.Focus();
    textBox.Select(textBox.Text.Length, 0);
  }

  private void buttonAddAttribute_Click(object sender, RoutedEventArgs e)
  {
    DncFieldSelectorDialog fieldSelectorDialog = new DncFieldSelectorDialog(true);
    fieldSelectorDialog.SetSortAttributesByNameByDefault(false);
    // ISSUE: method pointer
    fieldSelectorDialog.Filter += new FieldFilter((object) null, __methodptr(FilterSimpleTypesOnly));
    fieldSelectorDialog.OnApply += new EventHandler(this.fsd_OnApply);
    int num = (int) ((Form) fieldSelectorDialog).ShowDialog();
  }

  private void fsd_OnApply(object sender, EventArgs e)
  {
    if (!(sender is DncFieldSelectorDialog fieldSelectorDialog) || !fieldSelectorDialog.IsDirty)
      return;
    DncfFieldDef[] selectedFields = fieldSelectorDialog.SelectedFields;
    if (selectedFields.Length == 0)
      return;
    foreach (string serializedAttributesName in CApRenameToolManager.GetSerializedAttributesNames(selectedFields, '{', '}'))
      this.textBoxAppend.Text += serializedAttributesName;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    System.Windows.Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/renametool/rules/cuiappend.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  internal Delegate _CreateDelegate(Type delegateType, string handler)
  {
    return Delegate.CreateDelegate(delegateType, (object) this, handler);
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        this.rbPrefix = (System.Windows.Controls.RadioButton) target;
        break;
      case 2:
        this.rbSuffix = (System.Windows.Controls.RadioButton) target;
        break;
      case 3:
        this.radioButtonAppend = (System.Windows.Controls.RadioButton) target;
        break;
      case 4:
        this.textBoxAppend = (System.Windows.Controls.TextBox) target;
        this.textBoxAppend.IsEnabledChanged += new DependencyPropertyChangedEventHandler(this.textBox_IsEnabledChanged);
        break;
      case 5:
        this.textBoxEnum = (System.Windows.Controls.TextBox) target;
        break;
      case 6:
        this.textBoxStep = (System.Windows.Controls.TextBox) target;
        break;
      case 7:
        this.unlimitedChkBx = (System.Windows.Controls.CheckBox) target;
        break;
      case 8:
        this.buttonAddEnumerator = (System.Windows.Controls.Button) target;
        this.buttonAddEnumerator.Click += new RoutedEventHandler(this.buttonAddEnumerator_Click);
        break;
      case 9:
        this.buttonAddAttribute = (System.Windows.Controls.Button) target;
        this.buttonAddAttribute.Click += new RoutedEventHandler(this.buttonAddAttribute_Click);
        break;
      case 10:
        this.radioButtonTrim = (System.Windows.Controls.RadioButton) target;
        break;
      case 11:
        this.textBoxTrim = (System.Windows.Controls.TextBox) target;
        this.textBoxTrim.IsEnabledChanged += new DependencyPropertyChangedEventHandler(this.textBox_IsEnabledChanged);
        break;
      case 12:
        this.radioButtonTrimDigits = (System.Windows.Controls.RadioButton) target;
        break;
      case 13:
        this.btnOK = (System.Windows.Controls.Button) target;
        this.btnOK.Click += new RoutedEventHandler(this.btnOK_Click);
        break;
      case 14:
        this.btnCancel = (System.Windows.Controls.Button) target;
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
